/*
 * @Author: 周润玉|zhourunyu1@outlook.com(zhourunyu)
 * @Date: 2022-07-15 11:11:23
 * @LastEditors: 周润玉|zhourunyu1@outlook.com(zhourunyu)
 * @LastEditTime: 2022-07-20 09:56:58
 * @Description: 
 * @Administrator: 
 * @Copyright: 文件版本号
 */
import doT from '../../../../vendor/template/doT.js';
import curinventoryApi from '../../../common/api/cptv/curinventory.api.js';

let _vm;
const _page = {
    pageSize: 256,
    pageIndex: 0,
    totalPages: -1,

};
(function (window, document, $) {
    $(function () {
        // JS严格模式
        'use strict';
        $('body').attr('data-weui-theme', 'light'); // 强制光明模式
        _vm = new Vue({
            el: "#curinventory-page",
            data() {
                return {
                    quickQuery: '',
                    page: { ..._page },
                }
            },
            methods: {
            },
        });
        //_initDataTable();
        _initCommand();
        search();
    });

    /**
     *@file 列表展示
     *@Date :2022-07-15 13:15:11
     *@create周润玉
    */
    const _initDataTable = () => {
        let _data = _vm.page;
        curinventoryApi.postInventories(Object.assign({
            searchInfo: $('#search-index').val(),
        }, _data)).then(res => {
            $('#newToday').text(res.t);
            let _template = doT.template($('#curinventory-template').text());
            $('#curinventory-table-id').empty().append(_template({ list: res.rList.items }));
        });
    }

    /**
     *@file 命令初始化
     *@Date :2022-07-15 16:58:06
     *@create周润玉
    */
    const _initCommand = () => {
        //返回首页
        $('.returnMain').on('click', function () {
            location.href = '../../main.html';
        });

        //搜索框搜索
        $("#searchdiv form").submit(function () {
            _initDataTable();
            return false;
        });
    }

    const search = () => {
        let $searchInput = $('#search-index'),
            $searchClear = $('#search_clear'),
            $searchCancel = $('#search_cancel'),
            $searchResult = $('#searchResult'),
            $searchForm = $('#searchForm'),
            $searchBar = $('#searchBar'),
            $searchText = $('#searchText');
        //隐藏取消按钮
        $searchInput
            .on('blur', function () {
                if (!this.value.length) cancelSearch();
            })
            .on('input', function () {
                if (this.value.length) {
                    $searchResult.show();
                    $searchForm.attr('aria-expanded', 'true');
                } else {
                    $('#newToday').text('');
                    $('#search-index').val('');
                    $searchResult.hide();
                    $searchForm.attr('aria-expanded', 'false');
            }
        });
        $searchClear.on('click', function () {
            $('#newToday').text('');
            $('#search-index').val('');
            $('#curinventory-table-id').empty();
            return false;
        });
        $searchCancel.on('click', function () {
            $('#curinventory-table-id').empty();
            $searchInput.blur();
        });

        function cancelSearch() {
            hideSearchResult();
            $searchBar.removeClass('weui-search-bar_focusing');
            $searchText.show();
        }
        function hideSearchResult() {
            $searchResult.hide();
            $searchForm.attr('aria-expanded', 'false');
            $searchInput.val('');
        }
    }

})(window, document, jQuery);